* Updated initStats maintenance script
authorRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 15:54:20 +0000 (15:54 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 15:54:20 +0000 (15:54 +0000)
* Remove recountImages since it's now redundant

RELEASE-NOTES
maintenance/initStats.php
maintenance/recountImages.php [deleted file]

index dd1ab18..b4ba65a 100644 (file)
@@ -178,7 +178,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   formatted according to the current user's settings
 * (bug 218) Redirects do not support named anchors
 * (bug 5780) Thousands and decimal separators for Norwegian
-* Maintenance script to recount images and update the site statistics
+* Updated initStats maintenance script
 
 == Compatibility ==
 
index 9c1e1fa..0fd881f 100644 (file)
@@ -1,34 +1,57 @@
 <?php
 
+/**
+ * Maintenance script to re-initialise or update the site statistics table
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Brion Vibber
+ * @author Rob Church <robchur@gmail.com>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+$options = array( 'help', 'update' );
 require_once( 'commandLine.inc' );
-
+echo( "Refresh Site Statistics\n\n" );
 $dbr =& wfGetDB( DB_SLAVE );
+$fname = 'initStats';
+
+echo( "Counting total edits..." );
+$edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
+echo( "{$edits}\nCounting number of articles..." );
+
+$good  = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
+echo( "{$good}\nCounting total pages..." );
 
-$edits = $dbr->selectField( 'revision', 'COUNT(rev_id)', '' );
-$pages = $dbr->selectField( 'page', 'COUNT(page_id)',
-       array(
-               'page_namespace' => 0,
-               'page_is_redirect' => 0,
-               'page_len > 0',
-       )
-); // HACK APPROXIMATION
+$pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
+echo( "{$pages}\nCounting number of users..." );
 
-echo "$wgDBname: setting edits $edits, pages $pages\n";
+$users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
+echo( "{$users}\nCounting number of admins..." );
+
+$admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
+echo( "{$admin}\nCounting number of images..." );
+
+$image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
+echo( "{$image}\n\nUpdating site statistics..." );
 
 $dbw =& wfGetDB( DB_MASTER );
+$values = array( 'ss_total_edits' => $edits,
+                               'ss_good_articles' => $good,
+                               'ss_total_pages' => $pages,
+                               'ss_users' => $users,
+                               'ss_admins' => $admin,
+                               'ss_images' => $image );
+$conds = array( 'ss_row_id' => 1 );
+$views = array( 'ss_total_views' => 0 );
+                               
 if( isset( $options['update'] ) ) {
-       echo "(updating...)\n";
-       $dbw->update( 'site_stats',
-               array( 'ss_total_edits'   => $edits,
-                      'ss_good_articles' => $pages ),
-               array( 'ss_row_id' => 1 ) );
+       $dbw->update( 'site_stats', $values, $conds, $fname );
 } else {
-       $dbw->delete( 'site_stats', array( 'ss_row_id' => 1 ) );
-       $dbw->insert( 'site_stats',
-               array( 'ss_row_id'=> 1,
-                      'ss_total_views'   => 0,
-                      'ss_total_edits'   => $edits,
-                      'ss_good_articles' => $pages ) );
+       $dbw->delete( 'site_stats', $conds, $fname );
+       $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
 }
 
+echo( "done.\n\n" );
+
 ?>
\ No newline at end of file
diff --git a/maintenance/recountImages.php b/maintenance/recountImages.php
deleted file mode 100644 (file)
index 613082f..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-/**
- * Maintenance script to update the site_stats.ss_images field
- *
- * @package MediaWiki
- * @subpackage Maintenance
- * @author Rob Church <robchur@gmail.com>
- * @licence GNU General Public Licence 2.0 or later
- */
-
-require_once( 'commandLine.inc' );
-
-function recountImages() {
-       $dbw =& wfGetDB( DB_MASTER );
-       $count = $dbw->selectField( 'images', 'COUNT(*)', '', 'recountImages' );
-       # Replication safe update; set to NULL first to force the change to slaves
-       $dbw->update( 'site_stats', array( 'ss_images' => NULL ), array( 'ss_row_id' => 1 ), 'recountImages' );
-       $dbw->update( 'site_stats', array( 'ss_images' => $count ), array( 'ss_row_id' => 1 ), 'recountImages' );
-       return $count;
-}
-
-echo( "Updating image count in site statistics..." );
-recountImages();
-echo( "set to {$count}.\n\n" );
-
-?>
\ No newline at end of file